<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>人事管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
        <link rel="stylesheet" href="../../static/css/font.css">
    <link rel="stylesheet" href="../../static/css/xadmin.css">
     <script src="../../static/js/jquery-1.12.4.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/js/xadmin.js"></script>
</head>

<body>
    <div class="x-body layui-anim layui-anim-up">
        <form class="layui-form">

            <div class="layui-form-item">
                <label for="L_username" class="layui-form-label">
                    <span class="x-red">*</span>登录名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="loginname" name="loginname" lay-verify="required" 
                        autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>将会成为您唯一的登入名
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>昵称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="username" name="username" required="" lay-verify="required|nikename"
                        autocomplete="off" class="layui-input">
                </div>
				<div class="layui-form-mid layui-word-aux">
                    	昵称至少得3个字符！
                </div>
            </div>
	 		<div class="layui-form-item">
	 			<label class="layui-form-label">
                    <span class="x-red">*</span>状态
                </label>
                <div class="layui-input-inline">
		          <select name="status" id='status' lay-verify="required" >
		            <option value="">选择状态</option>
		            <option value="1">未审批</option>
		            <option value="2">正常</option>
		          </select>
		          </div>
	        </div>
            <div class="layui-form-item">
                <label for="L_pass" class="layui-form-label">
                    <span class="x-red">*</span>密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="L_pass" name="password" required="" lay-verify="pass" autocomplete="off"
                        class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    	密码必须6到12位字符！
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                    <span class="x-red">*</span>确认密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="L_repass" name="repass" required="" lay-verify="repass"
                        autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    	密码必须6到12位字符！
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                </label>
                <button id='submit' class="layui-btn" lay-filter="add" lay-submit="submit">
                    &nbsp;&nbsp;添加&nbsp;&nbsp;
                </button>
            </div>
        </form>
    </div>
    <script>
        layui.use(['form', 'layer'], function () {
            $ = layui.jquery;
            var form = layui.form
                , layer = layui.layer;

            //自定义验证规则
            form.verify({
                nikename: function (value) {
                    if (value.length < 2) {
                        return '昵称至少得2个字符！';
                    }
                }
                , pass: [/^[0-9a-zA-Z_]{6,12}$/, '密码必须6到12位字符！']
                , repass: function (value) {
                    if ($('#L_pass').val() != $('#L_repass').val()) {
                        return '两次密码不一致';
                    }
                }
            });

            //监听提交
            form.on('submit(add)', function (data) {
                //发异步，把数据提交,ajax 代码
                $.ajax({
                    url: '../../addUser.action',
                    type: 'post',
                    data: data.field,
                    success: function (data) {
                        if (data == 1) {
                            layer.alert(
                                "增加成功", { icon: 6 },
                                function () {
                                    // 获得frame索引
                                    var index = parent.layer.getFrameIndex(window.name);
                                    //关闭当前frame
                                    parent.layer.close(index);
                                    //修改成功后刷新父界面
                                    window.parent.location.reload();
                            });
                        }
                        else {
                        	 layer.alert("增加信息失败！", { icon: 2 })
                        }
                    },
                    error: function (e) {
                        layer.alert("error！提交失败！")
                    }
                });
                return false;
            });


        });
        
        $("#loginname").keyup(function(){
        	var name=$(this).val();
            $.ajax({
                url:"../../checkName.action",
                type:"get",
                data:{"loginname":name},
                success:function(data){
                 if(data==1){
                  //开启提交按钮
                	$("#submit").removeClass("layui-btn-disabled").attr("disabled",false);
                 }else {
                layer.msg('用户名已存在',{icon:7});
                  //把提交按钮关闭
                  $("#submit").addClass("layui-btn-disabled").attr("disabled",true)
                  
                 }

                },
                error:function(){
                 alert("执行异常!");
                }
               })
        })
    </script>

</body>

</html>